﻿// <copyright file="OutputEntry.cs" company="Horiba Medical">
//     Copyright (c) Horiba Medical. All rights reserved.
// </copyright>
// <summary>
//     Output entry class definition.
// </summary>

namespace DoxyOutParser.Parser
{
	using System;

	/// <summary>
	/// Provides an object to display log files entry in datagrid views.
	/// </summary>
	public class OutputEntry : IComparable<OutputEntry>
	{
		/// <summary>
		/// File name and path part of a warning log entry.
		/// </summary>
		private string fileNameAndPath;

		/// <summary>
		/// Line part of a warning log entry.
		/// </summary>
		private string line;

		/// <summary>
		/// Message type part of a warning log entry.
		/// </summary>
		private string messageType;

		/// <summary>
		/// Message details part of a warning log entry.
		/// </summary>
		private string messageDetails;

		/// <summary>
		/// Gets or sets the fileNameAndPath variable.
		/// </summary>
		/// <value>The new file name and path.</value>
		public string FileNameAndPath
		{
			get
			{
				return this.fileNameAndPath;
			}

			set
			{
				this.fileNameAndPath = value;
			}
		}

		/// <summary>
		/// Gets or sets the line variable.
		/// </summary>
		/// <value>The new line.</value>
		public string Line
		{
			get
			{
				return this.line;
			}

			set
			{
				this.line = value;
			}
		}

		/// <summary>
		/// Gets or sets the messageType variable.
		/// </summary>
		/// <value>The new message type.</value>
		public string MessageType
		{
			get
			{
				return this.messageType;
			}

			set
			{
				this.messageType = value;
			}
		}

		/// <summary>
		/// Gets or sets the messageDetails variable.
		/// </summary>
		/// <value>The new message details.</value>
		public string MessageDetails
		{
			get
			{
				return this.messageDetails;
			}

			set
			{
				this.messageDetails = value;
			}
		}

		#region IComparable<DoxygenOutputEntry> Members

		/// <summary>
		/// Implementation of the == operator for the OutputEntry class.
		/// </summary>
		/// <param name="entryA">Left operand.</param>
		/// <param name="entryB">Right operand.</param>
		/// <returns>Boolean indicating result of comparison.</returns>
		public static bool operator ==(OutputEntry entryA, OutputEntry entryB)
		{
			object objectA = (object)entryA;
			object objectB = (object)entryB;

			if (objectA == objectB)
			{
				return true;
			}

			if ((objectA == null) || (objectB == null))
			{
				return false;
			}

			return entryB.FileNameAndPath == entryA.FileNameAndPath
				&& entryB.Line == entryA.Line
				&& entryB.MessageDetails == entryA.MessageDetails
				&& entryB.MessageType == entryA.MessageType;
		}

		/// <summary>
		/// Implementation of the != operator for the OutputEntry class.
		/// </summary>
		/// <param name="entryA">Left operand.</param>
		/// <param name="entryB">Right operand.</param>
		/// <returns>Boolean indicating result of comparison.</returns>
		public static bool operator !=(OutputEntry entryA, OutputEntry entryB)
		{
			return !(entryA == entryB);
		}

		/// <summary>
		/// Implementation of the 'inferior to' operator for the OutputEntry class.
		/// </summary>
		/// <param name="entryA">Left operand.</param>
		/// <param name="entryB">Right operand.</param>
		/// <returns>Boolean indicating result of comparison.</returns>
		public static bool operator <(OutputEntry entryA, OutputEntry entryB)
		{
			return entryA.CompareTo(entryB) < 0;
		}

		/// <summary>
		/// Implementation of the 'superior to' operator for the OutputEntry class.
		/// </summary>
		/// <param name="entryA">Left operand.</param>
		/// <param name="entryB">Right operand.</param>
		/// <returns>Boolean indicating result of comparison.</returns>
		public static bool operator >(OutputEntry entryA, OutputEntry entryB)
		{
			return entryA.CompareTo(entryB) > 0;
		}

		/// <summary>
		/// Compares another OutputEntry to this one.
		/// </summary>
		/// <param name="other">The other OutputEntry.</param>
		/// <returns>Negative if this OutputEntry is considered inferior to the compared one, positive if it is considered superior, 0 if equals.</returns>
		public int CompareTo(OutputEntry other)
		{
			// Try to sort based on the Last Name column.
			int compareResult = System.String.Compare(
				this.FileNameAndPath,
				other.FileNameAndPath,
				StringComparison.Ordinal);

			// If the Last Names are equal, sort based on the First Name.
			if (compareResult == 0)
			{
				compareResult = System.String.Compare(
					this.Line,
					other.Line,
					StringComparison.Ordinal);
			}

			return compareResult;
		}

		/// <summary>
		/// Overrides the Equals method for an OutputEntry object.
		/// </summary>
		/// <param name="obj">The object to compare.</param>
		/// <returns>Boolean indicating if the object is equal to this OutputEntry.</returns>
		public override bool Equals(object obj)
		{
			if (obj == (object)this)
			{
				return true;
			}

			// Check for null and compare run-time types
			if (obj == null || this.GetType() != obj.GetType())
			{
				return false;
			}

			OutputEntry entry = (OutputEntry)obj;
			return this.FileNameAndPath == entry.FileNameAndPath
				&& this.Line == entry.Line
				&& this.MessageDetails == entry.MessageDetails
				&& this.MessageType == entry.MessageType;
		}

		/// <summary>
		/// Overrides the GetHashCode method for the OutputEntry class.
		/// </summary>
		/// <returns>A unique hashcode.</returns>
		public override int GetHashCode()
		{
			return (this.FileNameAndPath + "-" + this.Line + "-" + this.MessageDetails + "-" + this.MessageType).GetHashCode();
		}

		#endregion
	}
}
